package com.whc.api.client.fallback;

import com.whc.api.client.GoodsClient;
import com.whc.api.dto.GoodsCreateDto;
import com.whc.api.dto.OrderDto;
import com.whc.common.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;


@Slf4j
public class GoodsClientFallback implements FallbackFactory<GoodsClient> {

    @Override
    public GoodsClient create(Throwable cause) {
        return new GoodsClient() {
            @Override
            public Result<List<GoodsCreateDto>> selectByIds(List<Long> ids) {
                log.info("远程调用商品查询服务异常，返回空集合");
                return Result.error("商品查询异常，请稍后再试");
            }

            @Override
            public Result deductGoodsByIds(OrderDto orderDto) {
                log.info("远程调用商品扣减服务异常");
                return Result.error("扣减库存失败");
            }

            @Override
            public Result resetGoodsByIds(OrderDto orderDto) {
                log.info("远程调用商品恢复服务异常");
                return Result.error("恢复库存失败");
            }
        };
    }
}
